//
//  YunLeftTableViewController.swift
//  Wmsmobile
//
//  Created by wangshuning on 16/7/27.
//  Copyright © 2016年 hddden. All rights reserved.
//

import UIKit

import MMDrawerController

class YunLeftTableViewController: UITableViewController {

    var dataArr = NSMutableArray(capacity: 0)
    var dataArr1 = NSMutableArray(capacity: 0)
    var label:UILabel?
    //#MARK: – Lifecycle
    override func viewWillAppear(_ animated: Bool) {
        
        if UserDefaults.standard.bool(forKey: "Login") {
            //            let name = NSUserDefaults.standardUserDefaults().objectForKey("userName")as!String
            label!.text = userInfo!.userName
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
//        tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
       
        self.tableView.backgroundColor = UIColor.hexStringToUIColor("#535353")
        tableView.register(UINib(nibName: "LeftTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "LeftTableViewCell")
        
        tableView.register(UINib(nibName: "HDTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "HDTableViewCell")
        
        tableView.delegate = self
        tableView.dataSource = self
        
        let headerView = UIView.init(frame: CGRect(x: 0, y: 0, width: KscreenWidth, height: 187))
//        headerView.backgroundColor = UIColor.greenColor()
        let userIcon = UIImageView.init(frame: CGRect(x: 35, y: 80, width: 60, height: 60))
//        userIcon.backgroundColor = UIColor.redColor()
        userIcon.image = UIImage.init(named: "头像icon")
        headerView.addSubview(userIcon)
        label = UILabel.init(frame: CGRect(x: 110, y: 80, width: KscreenWidth - 220, height: 60))
        label!.textColor = UIColor.hexStringToUIColor("#ffffff")
//        label.backgroundColor = UIColor.redColor()
        label!.font = UIFont.systemFont(ofSize: 17)
        headerView.addSubview(label!)
        self.view.addSubview(headerView)
        tableView.tableHeaderView = headerView
        
        
        dataArr=["设置icon","意见反馈icon","退出登录icon"]
        dataArr1 = ["设置","意见反馈","退出登录"]
        self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none;
        //给TableView添加表头
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
//    func openViewController()  {
//        
//        let drawerShouldOpen = DrawerShouldOpen.mainDrawerShouldOpen;
//        if (drawerShouldOpen.numberOfCenterViews == 0) {
//            mm_drawerController.closeDrawerAnimated(true, completion: { (finished:Bool) in
//                drawerShouldOpen.flag = false
//            })
//        }else {
//            let mainVC = YunCangViewController()
//            let mianNVC = YunCenterViewController.init(rootViewController: mainVC)
//            
//            drawerShouldOpen.numberOfCenterViews = 0;
//            mm_drawerController.setCenterViewController(mianNVC, withCloseAnimation: true, completion: { (finished:Bool) in
//            })
//        }
//        
//    }

    //#MARK: – UITableViewDataSource

    override func numberOfSections(in tableView: UITableView) -> Int {

        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 3
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//        if indexPath.row == 0 {
//            let cell1 = tableView.dequeueReusableCellWithIdentifier("LeftTableViewCell", forIndexPath: indexPath)as! LeftTableViewCell
//            if NSUserDefaults.standardUserDefaults().boolForKey("Login") {
//                let name = NSUserDefaults.standardUserDefaults().objectForKey("userName")as!String
//                cell1.leftLabel.text = name
//            }
//            cell1.leftLabel.textColor = UIColor.hexStringToUIColor("#ffffff")
//            cell1.leftLabel.font = UIFont.systemFontOfSize(17)
//            cell1.leftImage.image = UIImage.init(named: "头像icon")
//            cell1.backgroundColor = UIColor.hexStringToUIColor("#535353")
//            cell1.selectionStyle = UITableViewCellSelectionStyle.Gray
//            return cell1
//            
//        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "HDTableViewCell", for: indexPath)as!HDTableViewCell
        cell.sectionLabel?.text = dataArr1[(indexPath as NSIndexPath).row] as? String
        cell.sectionLabel?.font = UIFont.systemFont(ofSize: 15)
        cell.sectionLabel?.textColor = UIColor.hexStringToUIColor("#ffffff")
        cell.sectionImage?.image = UIImage.init(named: dataArr[(indexPath as NSIndexPath).row] as! String)
        cell.backgroundColor = UIColor.hexStringToUIColor("#535353")
        cell.selectionStyle = UITableViewCellSelectionStyle.gray
        return cell
        
    }
    
    //#MARK: – UITableViewDelegate
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if (indexPath as NSIndexPath).row == 0 || (indexPath as NSIndexPath).row == 2{
            let array = [SetViewController(),UIViewController(),LoginViewController()]
            let mianNVC = YunCenterViewController.init(rootViewController: array[(indexPath as NSIndexPath).row])
            mm_drawerController.setCenterView(mianNVC, withCloseAnimation: true, completion: { (finished:Bool) in
            })
        }
        if (indexPath as NSIndexPath).row == 1 {
            PgyManager.shared().showFeedbackView()
        }
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return 45
    }
    
    override var preferredStatusBarStyle : UIStatusBarStyle {
        return UIStatusBarStyle.lightContent
    }


}
